#Descriptive Statistics of Experiment 1
#Alan Yan
#June 1st

#clear environment
rm(list = ls())

#load libraries
library(pacman)
p_load(tidyverse,
       stargazer)

#load data
dt <- read.csv("01-Experiment-1/data/04-clean-data/clean_data.csv", stringsAsFactors = FALSE, header = TRUE)

#descriptive statistics of the sample
dt %>%
  mutate(
    Gender = 
      case_when(
        gender == "female" ~ "Woman",
        gender == "male" ~ "Man",
        is.na(gender) == TRUE ~ "Unknown"
      )
  ) -> dt

#left column Table S4
table(dt$Gender) %>%
  prop.table() %>%
  as.data.frame() %>%
  mutate(Proportion = paste0(round(Freq*100, 2), "%")) %>%
  select(1,3) %>%
  setNames(., c("Gender", "Proportion")) %>%
  stargazer(summary = FALSE,
            rownames = FALSE,
            title = "Descriptive Statistics, Study 1")

#descriptive statistics by experimental condition
dt <- dt %>%
  mutate(
    `Experimental Condition` =
      case_when(
    group == "female" ~ "Female-named",
    group == "male" ~ "Male-named",
    group == "gen.neutral" ~ "Ambiguously-named",
    group == "no.name" ~ "Unnamed"
  )
  )

dt %>%
  group_by(Gender) %>%
  filter(`Experimental Condition` == "Female-named") %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)*100) %>%
  mutate(Percent = paste0(round(freq, 2), "%")) %>%
  select(4) %>%
  t() %>%
  as.data.frame() %>%
  cbind("Female-named", .) %>%
  setNames(., c("Experimental Condition", "Men", "Unknown Gender", "Women")) -> female.exp.cond

dt %>%
  group_by(Gender) %>%
  filter(`Experimental Condition` == "Male-named") %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)*100) %>%
  mutate(Percent = paste0(round(freq, 2), "%")) %>%
  select(4) %>%
  t() %>%
  as.data.frame() %>%
  cbind("Male-named", .) %>% 
  setNames(., c("Experimental Condition", "Men", "Unknown Gender", "Women")) -> male.exp.cond

dt %>%
  group_by(Gender) %>%
  filter(`Experimental Condition` == "Ambiguously-named") %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)*100) %>%
  mutate(Percent = paste0(round(freq, 2), "%")) %>%
  select(4) %>%
  t() %>%
  as.data.frame() %>%
  cbind("Ambiguously-named", .) %>% 
  setNames(., c("Experimental Condition", "Men", "Unknown Gender", "Women")) -> ambig.exp.cond

dt %>%
  group_by(Gender) %>%
  filter(`Experimental Condition` == "Unnamed") %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)*100) %>%
  mutate(Percent = paste0(round(freq, 2), "%")) %>%
  select(4) %>%
  t() %>%
  as.data.frame() %>%
  cbind("Unnamed", .) %>% 
  setNames(., c("Experimental Condition", "Men", "Unknown Gender", "Women")) -> unnamed.exp.cond

#Table S5
rbind(female.exp.cond,
      male.exp.cond,
      ambig.exp.cond,
      unnamed.exp.cond) %>%
  stargazer(summary = FALSE,
            rownames = FALSE,
            title = "Descriptive Statistics by Experimental Condition, Study 1")


